package com.googlecode.flair.builder
{
	import com.googlecode.flair.IFlairComponent;
	import com.googlecode.flair.editors.ComponentIcons;
	import com.googlecode.flair.mvc.ILabelProvider;
	
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	import mx.core.UIComponent;
	import mx.styles.CSSStyleDeclaration;

	public class FlairDesignerLabelProvider implements ILabelProvider
	{
		public function FlairDesignerLabelProvider()
		{
		}

		public function getIcon(object:Object):Class
		{
			if (!(object is IFlairComponent)) {
				return null;
			}
			var component : Object = IFlairComponent(object).component;
			var icon : Class = null;
			if (IFlairComponent(object).icon != null) {
				icon = IFlairComponent(object).icon;
			} else if (component is UIComponent) {
				icon = UIComponent(component).getStyle("icon");
			} else if (component is CSSStyleDeclaration) {
				icon = CSSStyleDeclaration(component).getStyle("icon");
			} 
			if (!icon) {
				var clasz : Class = getDefinitionByName(getQualifiedClassName(component)) as Class;
				icon = ComponentIcons.instance.getIcon(clasz);
			}
			return icon;
		}
		
		public function getLabel(object:Object):String
		{
			if (!(object is IFlairComponent)) {
				return null;
			}
			return IFlairComponent(object).componentName;
		}
		
	}
}